package com.biz.primus.ms.sms.service.checker;

import com.biz.primus.model.misc.exception.ApiException;
import com.biz.primus.model.misc.vo.ChannelBasedAuth;
import com.biz.primus.model.misc.vo.ShortMessageVo;
import com.biz.primus.ms.sms.service.internal.FlowControlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author yanweijin
 * @date 2017/5/31
 */

@Component
public class FlowControlChecker extends SendCheckerAdapter{


	@Autowired
	private FlowControlService flowControlService;

	@Override
	public void check(ChannelBasedAuth cba) throws ApiException {
		if(cba instanceof ShortMessageVo){
			flowControlService.checkFlowControl((ShortMessageVo)cba);
		}
	}

	@Override
	public void afterException(ChannelBasedAuth sm, Exception e) {
		if(sm instanceof ShortMessageVo){
			flowControlService.removeFlowRecord((ShortMessageVo)sm);
		}
	}

	@Override
	public int getOrder() {
		return 55;
	}


}
